package com.example.demo.sort;

import java.util.Arrays;

/**
 * @author void
 * @date 2022/2/25 16:24
 * @desc 冒泡排序
 * 时间复杂度 平均:O(n*n) 最坏:O(n*n) 最好O(n)
 * https://www.cnblogs.com/onepixel/p/7674659.html
 */
public class BubbleSort {

    public static void main(String[] args) {
        int[] numbers = {26,3,5,15,6,2};
        
        //第几轮循环冒泡
        for(int i=0;i<numbers.length-1;i++){
            //比较该轮每个相邻元素
            for(int j=0;j<numbers.length-1-i;j++){
                if(numbers[j]>numbers[j+1]){
                    int temp = numbers[j];
                    numbers[j] = numbers[j+1];
                    numbers[j+1] = temp;
                }
            }
        }
        System.out.println(Arrays.toString(numbers));
    }
}
